﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyCommerce.Presentation.GeneralParameters.IViews;
using Innova.Microfinanzas.BusinessEntities;
using MyCommerce.Business.GeneralParameters;

namespace MyCommerce.Presentation.GeneralParameters.Presenters
{
    public class CustomerRegistrationPresenter
    {
        private ICustomerRegistrationView pViewToPresent;

        public CustomerRegistrationPresenter(ICustomerRegistrationView vView)
        {
            pViewToPresent = vView;
            pViewToPresent.OnCancel += new EventHandler(pViewToPresent_OnCancel);
            pViewToPresent.OnSave += new EventHandler(pViewToPresent_OnSave);
        }

        private void pViewToPresent_OnSave(object sender, EventArgs e)
        {
            Customer objCustomer = pViewToPresent.Get();
            if (objCustomer != null)
            {
                CustomerManager customerMgr = new CustomerManager();
                pViewToPresent.SetWindowResult(customerMgr.CreateUpdateCustomer(objCustomer));
            }
        }

        private void pViewToPresent_OnCancel(object sender, EventArgs e)
        {
            pViewToPresent.ClearView();
            pViewToPresent.SetWindowResult(null);
        }
    }
}
